import settingApi from 'yuxin-base/src/api/setting-api'
import houseApi from '@/api/house-api'
import {Empty, FormInstance, Modal, message} from 'ant-design-vue'
import {computed, createVNode, onMounted, reactive, ref, watch, watchEffect} from 'vue'
/** 决策合同设置 */
const contractDecision = ref<any>({
	disabledeposit: false,
	shiftProperty: false,
	shiftPropertyType: [],
	depositType: []
})

const init = async () => {
	await settingApi.getDecisionList({module: 'CONTRACT'}).then(({data}) => {
		const management_fee = data.find(e => e.mark === 'MANAGEMENT_FEE_AUTO_GENERATE')
		const deposit_auto = data.find(e => e.mark === 'CONTRACT_DEPOSIT_GENERATE')
		// 物业费生成配置
		const management_fee_source = JSON.parse(management_fee.value || '[]')
		contractDecision.value.shiftPropertyType = management_fee_source
		contractDecision.value.shiftProperty = management_fee.onOff === '1'
		// 合同押金生成配置
		const deposit_auto_source = JSON.parse(deposit_auto.value || '[]')
		contractDecision.value.disabledeposit = deposit_auto_source === 2 ? true : false
		contractDecision.value.depositType = deposit_auto_source
	})
}




export const validateFee = async (id: string) => {
	init()
	const {data} = await houseApi.getHouseRoom(id)

	const errorList:any = []
	const {communityPropertyPrice, propertyPrice, depositPrice} = data
	const validatePorperty = contractDecision.value.shiftProperty && contractDecision.value.shiftPropertyType === 1
	const validateDeposit = contractDecision.value.disabledeposit
	const validatePorpertyByArea = contractDecision.value.shiftProperty && contractDecision.value.shiftPropertyType === 2
	if (validatePorperty && !propertyPrice) {
		errorList.push({name: '房型物业费'})
	}
	if (validatePorpertyByArea && !communityPropertyPrice) {
		errorList.push({name: '物业费单价'})
	}
	if (validateDeposit && !depositPrice) {
		errorList.push({name: '房型押金'})
	}
	const nameStr = errorList.map(e => e.name).join('、')
	errorList.length && message.error(`未配置${nameStr}，无法操作，请先编辑房源进行配置`)
	return !errorList.length
}
